// @FileName  :fullyArranged.c
// @Time      :2024/3/1 10:27
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>

int a[10010], ans[10010];

void print(int n) {
    for (int i = 0; i < n; i++)
        printf("%d ", ans[i]);
    printf("\n");
}

void solve(int x, int n) {
    if (x == n) print(n);
    for (int i = 1; i <= n; i++)
        if (a[i] == 0) {
            a[i] = 1, ans[x] = i;
            solve(x + 1, n);
            a[i] = 0;
        }
}

int main() {
    int n;
    scanf("%d", &n);
    solve(0, n);
    return 0;
}